layui.define(['form', 'table'], function(exports) {
    var $ = layui.$, table = layui.table, form = layui.form;

    var placeId = $('input[name="placeId"]').val();

    table.render({
        elem: '#LAY-table'
        ,url: layui.setter.webRoot + '/pcl/place/cost/item/list.data'
        ,where:{placeId:placeId}
        ,method: 'post'
        ,parseData: function (res) {
            return {
                "code": res.code,
                "msg": res.msg,
                "count": res.body.total,
                "data": res.body.data
            };
        }
        ,response: {statusCode: 200}
        ,cols: [[
            {field: 'deviceTypeId', title: '设备类型'}
            ,{field: 'deviceTypeName', title: '设备类型名称'}
            ,{field: 'feeTemplateId', title: "收费模版ID"}
            ,{field: 'feeTemplateName', title: '收费模版名称'}
            ,{title: '操作', width: 120, align:'center', fixed: 'right', toolbar: '#LAY-table-toolbar'}
        ]]
        ,page: true
        ,limit: 30
        ,height: 'full-220'
        ,text: '对不起，加载出现异常！'
    });

    //监听搜索
    form.on('submit(LAY-search)', function(data){
        var field = data.field;
        //执行重载
        table.reload('LAY-table', {
            where: field
        });
    });

    //事件
    var active = {
        changeTemplate:function (obj){
            layer.open({
                type: 2
                ,title: '切换收费模版'
                ,content: layui.setter.webRoot + '/pcl/place/cost/change/list.html?placeId='+placeId+'&deviceTypeId='+obj.data.deviceTypeId
                ,maxmin: true
                ,area: ['80%', '80%']
                ,btn: ['取消']
                ,yes:function (index, layero){
                    layer.close(index); //关闭弹层
                    table.reload('LAY-table');
                }
                ,cancel:function (){
                    table.reload('LAY-table');
                }
            });
        }
    }

    table.on('tool(LAY-table)', function(obj){
        var type = obj.event ;
        active[type] ? active[type].call(this,obj) : '';
    });

    exports('pcl_place_cost_list', {})
})